package com.websecondhand;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {
    private String message;
    private Integer code;
    private Map<String, Object> data;

    private R() {
        data = new HashMap<>();
    }

    public R addData(String key, Object val) {
        data.put(key, val);
        return this;
    }

    public R changeCode(Integer code) {
        this.code = code;
        return this;
    }

    public R changeMessage(String message) {
        this.message = message;
        return this;
    }

    public R putAll(Map<String, Object> data) {
        this.data.putAll(data);
        return this;
    }

    public static R ok() {
        R r = new R();
        r.setCode(Constant.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    public static R error() {
        R r = new R();
        r.setCode(Constant.FAILED);
        r.setMessage("失败");
        return r;
    }
}
